import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
url = r"D:\PythonProjects\python\UI自动化测试\02\注册A.html"
driver.get(url)
driver.minimize_window()
"""
需求：打开‘注册A.html’页面，完成以下操作
1). 填写注册信息
2). 截图保存
"""
# 1 填写注册信息
driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin")
driver.find_element(By.CSS_SELECTOR, "#passwordA").send_keys("123456")
driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("13749207799")
driver.find_element(By.CSS_SELECTOR, "#emailA").send_keys("123456@qq.com")
# 2 截图放到img目录
# driver.get_screenshot_as_file("../img/img01.jpg")
# 动态获取文件名称，使用时间戳
# driver.get_screenshot_as_file("../img/img02_%s.jpg" % (time.strftime("%Y_%m_%d_%H_%M_%S")))
driver.get_screenshot_as_file("../img/img03_{}.png".format(time.strftime("%Y_%m_%d_%H_%M_%S")))

time.sleep(3)
driver.quit()
